package TuLin.Video;

public class VolatileAtomicTest {
    public static volatile int num = 0;

    //public static void increase() {
    public static synchronized void increase() {
        num++;
    }

    public static void main(String[] args) throws Exception{
        Thread[] threads = new Thread[10];
        for (int i=0; i<threads.length; i++) {
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {
                    for (int i=0; i<1000; i++){
                        increase();
                    }
                }
            });
            threads[i].start();
        }

        for (Thread t : threads) {
            t.join();
        }
        System.out.println(num);
    }
}
